﻿#include "SurfaceElectricFieldMapSelectDataDialog.h"
#include "BaseWidget/IdaWidgetHelper.h"
#include "BaseModule/IBaseSignal.h"

namespace pst
{
    SurfaceElectricFieldMapSelectDataDialog::SurfaceElectricFieldMapSelectDataDialog(QWidget* parent)
        : IdaDialogFrame(parent)
    {
        ui.setupUi(this);
        setWindowTitle(QStringLiteral("表面分布图"));
        IdaWidgetHelperInstance->setMainButtonStyle(ui.pushButton_accept);
        connect(ui.pushButton_accept, &QPushButton::clicked, this, &SurfaceElectricFieldMapSelectDataDialog::slot_buttonBox_accepted);
        connect(ui.pushButton_reject, &QPushButton::clicked, this, &SurfaceElectricFieldMapSelectDataDialog::slot_buttonBox_rejected);
    }

    SurfaceElectricFieldMapSelectDataDialog::~SurfaceElectricFieldMapSelectDataDialog()
    {
    }

    //void SurfaceElectricFieldMapSelectDataDialog::setValueNameList(const QList<FieldGraphGenerator::ArrayInformation>& valueNameList)
    //{
    //    m_valueNameList = valueNameList;
    //    ui.comboBox_chooseValue->clear();
    //    for (const auto& i : m_valueNameList)
    //    {
    //        ui.comboBox_chooseValue->addItem(i.arrayName);
    //    }
    //}

    //QList<FieldGraphGenerator::ArrayInformation> SurfaceElectricFieldMapSelectDataDialog::getValueNameList()
    //{
    //    return m_valueNameList;
    //}

    void SurfaceElectricFieldMapSelectDataDialog::setInfomationGraph3DBasical(InfomationGraph3DBasical* info)
    {
        m_addedArrayList.clear();
        m_info = info;
        for (const auto& i : m_info->m_allPointArray)
        {
            if (i.arrayComponent == 1)
            {
                ui.comboBox_chooseValue->addItem(i.arrayName);
                m_addedArrayList.append(i);
            }
        }

        for (const auto& i : m_info->m_allCellArray)
        {
            if (i.arrayComponent == 1)
            {
                ui.comboBox_chooseValue->addItem(i.arrayName);
                m_addedArrayList.append(i);
            }
        }

        if (!ui.comboBox_chooseValue->count())
            slot_buttonBox_accepted();
    }

    InfomationGraph3DBasical* SurfaceElectricFieldMapSelectDataDialog::getInfomationGraph3DBasical()
    {
        return m_info;
    }

    void SurfaceElectricFieldMapSelectDataDialog::slot_buttonBox_accepted()
    {
        auto index = ui.comboBox_chooseValue->currentIndex();
        if (index != -1 && m_addedArrayList.size())
        {
            m_info->m_currentScalarArray = m_addedArrayList[index];
        }
        else
        {
            index = -1;
        }

        QStringList geometryFileName = m_info->m_geometryFileName;
        QString geometryFileNameStr = geometryFileName.join(",");

        QStringList _pyCodes{};
        _pyCodes += QString("surfaceelectricfieldgraph = PostProcessing.SurfaceElectricFieldGraph()");
        _pyCodes += QString("surfaceelectricfieldgraph.setCurrentIndex(%1)").arg(index);
        _pyCodes += QString("surfaceelectricfieldgraph.setReaderIndex(%1)").arg(m_info->readerIndex);
        _pyCodes += QString("surfaceelectricfieldgraph.setReaderType('%1')").arg(m_info->readerType);
        _pyCodes += QString("surfaceelectricfieldgraph.setGraphType(%1)").arg((int)(m_info->m_graphType));
        _pyCodes += QString("surfaceelectricfieldgraph.setFilePath('%1')").arg(m_info->m_filePath);
        _pyCodes += QString("surfaceelectricfieldgraph.setName('%1')").arg(m_info->m_name.toUtf8().data());
        _pyCodes += QString("surfaceelectricfieldgraph.setGeometryFileName('%1')").arg(geometryFileNameStr.toUtf8().data());
        _pyCodes += QString("surfaceelectricfieldgraph.setIsOpenNewWindow('%1')").arg(m_isOpenNewWindow);
        _pyCodes += QString("surfaceelectricfieldgraph.create()");
        emit IBaseSignalInstance->signal_execPYCode(_pyCodes, true, false);

        m_info->m_valueGroupNameIndex = index;
        this->hideWindow();
        signal_sentChosenArrayInfo(m_info, m_isOpenNewWindow);
        this->close();
    }

    void SurfaceElectricFieldMapSelectDataDialog::slot_buttonBox_rejected()
    {
        this->close();
    }
}
